package com.yidu.t299.service.chr.impl;

import com.yidu.t299.dao.chr.GradesMapper;
import com.yidu.t299.domain.chr.Grades;
import com.yidu.t299.service.chr.GradesBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class GradesBizImpl implements GradesBiz {
    @Autowired
    private GradesMapper gradesMapper;
    @Override
    public List<Grades> selectByLesson(int rows, int page, String condition) {
        return gradesMapper.selectBylesson(rows,page,condition);
    }

    @Override
    public int selectByStudentName(int studentId, int lessonId) {
        return gradesMapper.selectByStudentName(studentId,lessonId);
    }

    @Override
    public String getCondition(String studentName,String className) {
        // 定义条件字符串变量，初始值为空格字符串
        String condition = " ";
        //自定义过滤条件(学员名称和校区名称)
        if (studentName != null && studentName.trim().length() != 0) {
            condition += " and sm.student_name like '%" + studentName+"%'";
        }
        if (className != null && className.trim().length() != 0) {
            condition += " and c.class_name like '%" + className+"%'";
        }
        // 返回条件字符串
        return condition;
    }

    @Override
    public int selectSumlesson(int studentId) {
        return gradesMapper.selectSumlesson(studentId);
    }
}
